//
//  SMPassWordTableViewController.m
//  SaveMoney
//
//  Created by user on 2018/11/27.
//  Copyright © 2018年 Sunflower. All rights reserved.
//

#import "SMPassWordTableViewController.h"

@interface SMPassWordTableViewController ()
@property (weak, nonatomic) IBOutlet SBBaseTextField *oldPassword;
@property (weak, nonatomic) IBOutlet SBBaseTextField *nePassword;
@property (weak, nonatomic) IBOutlet SBBaseTextField *againNewPassword;

@end

@implementation SMPassWordTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"密码修改";
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 1 || indexPath.row == 3 || indexPath.row == 5) {
        return SBScaleNumber(50);
    } else if (indexPath.row == 0) {
        return SBScaleNumber(40);
    } else {
        return SBScaleNumber(20);
    }
    
}
- (IBAction)buttonAction:(id)sender {
    [SVProgressHUD show];
    __weak typeof(self) weakSelf = self;
    [[NetworkAction sharedAction] changePasswordWithPhone:[SMUserInfoModel sharedStorage].phone oldPwd:_oldPassword.text password:_againNewPassword.text success:^(id model, NSString *message) {
        [SVProgressHUD showSuccessWithStatus:message];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf.navigationController popToRootViewControllerAnimated:YES];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                if ([weakSelf.delegate respondsToSelector:@selector(changePassword)]) {
                    [weakSelf.delegate changePassword];
                }
            });
        });
    } failuer:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:error.localizedDescription];
    }];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
